const DB = require('../tools/mysql')

module.exports = async ctx => {

    const pass = await DB('admin').where('code', 'admin').select('password')

    if (pass[0].password == ctx.request.body.pass1) {
        const code = await DB('admin').where('code', 'admin').update('password', ctx.request.body.pass2)
        if (code == 1) {
            ctx.body = {
                code: 1,
                msg: '密码修改成功。'
            }
        } else {
            ctx.body = {
                code: 0,
                msg: '密码修改失败。'
            }
        }
    } else {
        ctx.body = {
            code: 0,
            msg: '原始密码错误。'
        }
    }

}